package Frames;

import Beans.Cliente;
import Beans.Pessoa;
import DataBase.ClienteDAO;
import DataBase.PessoaDAO;
import java.awt.event.KeyEvent;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRResultSetDataSource;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.view.JasperViewer;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Tela_Produto.java
 *
 * Created on 04/07/2011, 15:49:18
 */
/**
 *
 * @author Jaguar
 */
public class Tela_Cliente extends javax.swing.JFrame {

    /** Creates new form Tela_Produto */
    Cliente c = null;
    Pessoa p = null;

    public Tela_Cliente() {
        initComponents();
        c = new Cliente();
        p = new Pessoa();
        p.setLoad(false);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        txtNome = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        btnCadastrar = new javax.swing.JButton();
        btnLimpar = new javax.swing.JButton();
        txtEndereco = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        txtTel1 = new javax.swing.JTextField();
        txtTel2 = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        txtCpf = new javax.swing.JTextField();
        VerificarCpf = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jPanel7 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        Bt_Pesq_Consu = new javax.swing.JButton();
        Bt_Consu_List = new javax.swing.JButton();
        jPanel8 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblPesquisaCliente = new javax.swing.JTable();
        txtPesquisa = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jPanel9 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        txtPesquisaExcluir = new javax.swing.JTextField();
        btnExcluir = new javax.swing.JButton();
        Bt_Exc_Pesq = new javax.swing.JButton();
        jPanel10 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblPesquisaExc = new javax.swing.JTable();
        jPanel4 = new javax.swing.JPanel();
        jPanel11 = new javax.swing.JPanel();
        jPanel12 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        txtEnderecoAlterar = new javax.swing.JTextField();
        txtTel2Alterar = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        txtTel1Alterar = new javax.swing.JTextField();
        jComboBoxStatus = new javax.swing.JComboBox();
        txtNomeAlterar = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jPanel13 = new javax.swing.JPanel();
        btnAlterar = new javax.swing.JButton();
        Bt_Alt_Limp = new javax.swing.JButton();
        Bt_Pesq_Alt = new javax.swing.JButton();
        txtPesquisaAlterar = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("tela_produto"); // NOI18N
        setUndecorated(true);

        jTabbedPane1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTabbedPane1KeyPressed(evt);
            }
        });

        jPanel5.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 255), 2, true));

        jLabel2.setText("Nome:");

        jLabel4.setText("Endereço:");

        jPanel6.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 204), 1, true));

        btnCadastrar.setText("Cadastrar");
        btnCadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCadastrarActionPerformed(evt);
            }
        });

        btnLimpar.setText("Limpar");
        btnLimpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimparActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(btnLimpar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnCadastrar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnCadastrar)
                .addGap(18, 18, 18)
                .addComponent(btnLimpar)
                .addContainerGap(22, Short.MAX_VALUE))
        );

        jLabel1.setText("Fone 1:");

        jLabel8.setText("Fone 2:");

        try{
            javax.swing.text.MaskFormatter format_textField = new javax.swing.text.MaskFormatter("########");

            format_textField.setValidCharacters
            ("0123456789");
            txtTel1  = new javax.swing.JFormattedTextField(format_textField);
        }catch(Exception ex ){}

        try{
            javax.swing.text.MaskFormatter format_textField = new javax.swing.text.MaskFormatter("########");

            format_textField.setValidCharacters
            ("0123456789");
            txtTel2  = new javax.swing.JFormattedTextField(format_textField);
        }catch(Exception ex ){}

        jLabel13.setText("CPF");

        try{
            javax.swing.text.MaskFormatter format_textField = new javax.swing.text.MaskFormatter("###########");

            format_textField.setValidCharacters
            ("0123456789");
            txtCpf   = new javax.swing.JFormattedTextField(format_textField);
        }catch(Exception ex ){}
        txtCpf.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCpfActionPerformed(evt);
            }
        });
        txtCpf.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtCpfKeyPressed(evt);
            }
        });

        VerificarCpf.setText("Verificar");
        VerificarCpf.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                VerificarCpfActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel13)
                    .addComponent(jLabel2)
                    .addComponent(jLabel4)
                    .addComponent(jLabel1)
                    .addComponent(jLabel8))
                .addGap(18, 18, 18)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtEndereco, javax.swing.GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE)
                            .addComponent(txtNome, javax.swing.GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE)
                            .addComponent(txtCpf)
                            .addComponent(txtTel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(VerificarCpf)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48, Short.MAX_VALUE)
                        .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(txtTel2, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(85, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel13)
                            .addComponent(txtCpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(VerificarCpf))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(9, 9, 9)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(txtEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtTel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addGap(13, 13, 13)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtTel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8))))
                .addContainerGap(53, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(399, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Cadastro", jPanel1);

        jPanel7.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 204), 2, true));

        jLabel5.setText("Nome:");

        Bt_Pesq_Consu.setText("Pesquisar");
        Bt_Pesq_Consu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Bt_Pesq_ConsuActionPerformed(evt);
            }
        });

        Bt_Consu_List.setText("Listar");
        Bt_Consu_List.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Bt_Consu_ListActionPerformed(evt);
            }
        });

        jPanel8.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 204), 1, true));

        tblPesquisaCliente.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nome", "cpf", "Endereco", "Fone1", "Fone2"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tblPesquisaCliente);

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 525, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(19, Short.MAX_VALUE))
        );

        txtPesquisa.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtPesquisaKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtPesquisa, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(Bt_Pesq_Consu)
                        .addGap(18, 18, 18)
                        .addComponent(Bt_Consu_List, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(218, Short.MAX_VALUE))))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtPesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Bt_Consu_List)
                    .addComponent(Bt_Pesq_Consu))
                .addGap(13, 13, 13)
                .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(19, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(386, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(54, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Consulta", jPanel2);

        jPanel9.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 204), 2, true));

        jLabel6.setText("Nome:");

        txtPesquisaExcluir.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtPesquisaExcluirKeyPressed(evt);
            }
        });

        btnExcluir.setText("Excluir");
        btnExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExcluirActionPerformed(evt);
            }
        });

        Bt_Exc_Pesq.setText("Pesquisar");
        Bt_Exc_Pesq.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Bt_Exc_PesqActionPerformed(evt);
            }
        });

        jPanel10.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 204), 1, true));

        tblPesquisaExc.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Código", "Nome", "cpf", "Endereço", "Fone 1", "Fone 2"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Object.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(tblPesquisaExc);

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 327, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtPesquisaExcluir, javax.swing.GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Bt_Exc_Pesq)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(12, 12, 12)))
                .addContainerGap())
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtPesquisaExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Bt_Exc_Pesq)
                    .addComponent(btnExcluir))
                .addGap(11, 11, 11)
                .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(19, 19, 19))
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(558, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(53, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Exclusão", jPanel3);

        jPanel11.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 204), 2, true));

        jPanel12.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.blue, java.awt.Color.blue, java.awt.Color.blue, java.awt.Color.blue));

        jLabel9.setText("Endereço:");

        jLabel10.setText("Status:");

        jLabel11.setText("Fone 2:");

        try{
            javax.swing.text.MaskFormatter format_textField = new javax.swing.text.MaskFormatter("########");

            format_textField.setValidCharacters
            ("0123456789");
            txtTel2Alterar     = new javax.swing.JFormattedTextField(format_textField);
        }catch(Exception ex ){}

        jLabel12.setText("Fone 1:");

        try{
            javax.swing.text.MaskFormatter format_textField = new javax.swing.text.MaskFormatter("########");

            format_textField.setValidCharacters
            ("0123456789");
            txtTel1Alterar     = new javax.swing.JFormattedTextField(format_textField);
        }catch(Exception ex ){}

        jComboBoxStatus.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ativado", "desativado" }));

        jLabel7.setText("Nome:");

        javax.swing.GroupLayout jPanel12Layout = new javax.swing.GroupLayout(jPanel12);
        jPanel12.setLayout(jPanel12Layout);
        jPanel12Layout.setHorizontalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel12Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel12Layout.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jComboBoxStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel12Layout.createSequentialGroup()
                            .addComponent(jLabel11)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(txtTel2Alterar, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel12Layout.createSequentialGroup()
                            .addGroup(jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel7))
                            .addGap(4, 4, 4)
                            .addGroup(jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(txtNomeAlterar, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(txtEnderecoAlterar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
                                .addComponent(txtTel1Alterar, javax.swing.GroupLayout.Alignment.LEADING)))))
                .addContainerGap(122, Short.MAX_VALUE))
        );
        jPanel12Layout.setVerticalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel12Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtNomeAlterar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(txtEnderecoAlterar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(txtTel1Alterar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(txtTel2Alterar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jComboBoxStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel13.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 255), 1, true));

        btnAlterar.setText("Alterar");
        btnAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAlterarActionPerformed(evt);
            }
        });

        Bt_Alt_Limp.setText("Limpar");
        Bt_Alt_Limp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Bt_Alt_LimpActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel13Layout = new javax.swing.GroupLayout(jPanel13);
        jPanel13.setLayout(jPanel13Layout);
        jPanel13Layout.setHorizontalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel13Layout.createSequentialGroup()
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel13Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(btnAlterar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel13Layout.createSequentialGroup()
                        .addContainerGap(22, Short.MAX_VALUE)
                        .addComponent(Bt_Alt_Limp)))
                .addContainerGap())
        );
        jPanel13Layout.setVerticalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel13Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(btnAlterar)
                .addGap(18, 18, 18)
                .addComponent(Bt_Alt_Limp)
                .addContainerGap(42, Short.MAX_VALUE))
        );

        Bt_Pesq_Alt.setText("Pesquisar");
        Bt_Pesq_Alt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Bt_Pesq_AltActionPerformed(evt);
            }
        });

        txtPesquisaAlterar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtPesquisaAlterarKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel11Layout.createSequentialGroup()
                        .addComponent(txtPesquisaAlterar, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(Bt_Pesq_Alt, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(306, 306, 306))
                    .addGroup(jPanel11Layout.createSequentialGroup()
                        .addComponent(jPanel12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 55, Short.MAX_VALUE)
                        .addComponent(jPanel13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel11Layout.createSequentialGroup()
                .addContainerGap(24, Short.MAX_VALUE)
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Bt_Pesq_Alt)
                    .addComponent(txtPesquisaAlterar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(361, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Alteração", jPanel4);

        jButton2.setText("Relatório");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(803, Short.MAX_VALUE)
                .addComponent(jButton2)
                .addGap(104, 104, 104))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 278, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2)
                .addContainerGap(24, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCadastrarActionPerformed
        try {

            ClienteDAO cd = new ClienteDAO();
            PessoaDAO pd = new PessoaDAO();
            System.out.println("Antes de tudo ");

            //Verifica se os Campos foram preenchidos 
            if (!txtCpf.getText().equals("") & !txtNome.getText().equals("") & !txtEndereco.getText().equals("")
                    & !txtTel1.getText().equals("") & !txtTel2.getText().equals("")) {
                System.out.println("Testes campos");
                //Verifica se os caracteres conrrespondentes ao cpf digitado são de um CPF válido
                if (ValidacaoCpf.calculaCPF(txtCpf.getText())) {
                    System.out.println("Teste cpf");
                    //Verifica se existe um funcionario com este Cpf
                    if (!cd.verificarCliente(txtCpf.getText())) {
                        System.out.println("Antes do Teste");
                        pd.verificarPessoa(txtCpf.getText());
                        System.out.println("Teste Cliente");
                        //verifica se exite uma pessoa com este Cpf

                        if (!pd.verificarPessoa(txtCpf.getText())) {
                            System.out.println("Testes Pessoa");
                            c = new Cliente();
                            c.setCpf(txtCpf.getText());
                            c.setNome(txtNome.getText());
                            c.setEndereco(txtEndereco.getText());
                            c.setTel1(txtTel1.getText());
                            c.setTel2(txtTel2.getText());

                            c.setStatus("ativado");
                            if (pd.inserirPessoa(c) & cd.inserirCliente(c)) {
                                JOptionPane.showMessageDialog(null, " Cliente " + c.getNome() + " Cadastrado com sucesso ");
                            } else {
                                JOptionPane.showMessageDialog(null, " Erro ao tentar cadastrar ");
                            }

                            //caso haja uma pessoa com este cpf
                        } else {
                            System.out.println("senao Pessoa");
                            if (!p.isLoad()) {
                                System.out.println("senao Pessoa 2 ");
                                p = pd.pesquisa(txtCpf.getText());
                                txtNome.setText(p.getNome());
                                txtNome.setEditable(false);
                                txtEndereco.setText(p.getEndereco());
                                txtEndereco.setEditable(false);
                                txtTel1.setText(p.getTel1());
                                txtTel1.setEditable(false);
                                txtTel2.setText(p.getTel2());
                                txtTel2.setEditable(false);

                                p.setLoad(true);
                                JOptionPane.showMessageDialog(null, " Existe uma Pessoa Cadastrada com este Cpf \n"
                                        + "Para completar o cadastro preencha os campos em branco ");
                            } else {
                                System.out.println("Pessoa LOAD");
                                c.setCpf(txtCpf.getText());
                                c.setNome(txtNome.getText());
                                c.setEndereco(txtEndereco.getText());
                                c.setTel1(txtTel1.getText());
                                c.setTel2(txtTel2.getText());

                                c.setStatus("ativado");
                                if (cd.inserirCliente(c)) {
                                    JOptionPane.showMessageDialog(null, "Cliente " + c.getNome() + " Cadastrado com sucesso ");
                                } else {
                                    JOptionPane.showMessageDialog(null, " Erro ao tentar cadastrar ");
                                }
                            }
                        }
                        //caso haja um funcionario com este cpf
                    } else {
                        System.out.println("Senao Funcionario");
                        c = cd.pesquisa(txtCpf.getText());
                        txtNome.setText(c.getNome());
                        txtNome.setEditable(false);
                        txtEndereco.setText(c.getEndereco());
                        txtEndereco.setEditable(false);
                        txtTel1.setText(c.getTel1());
                        txtTel1.setEditable(false);
                        txtTel2.setText(c.getTel2());
                        txtTel2.setEditable(false);

                        //testa se o Status do Funcionario está ou Desativado
                        if (c.getStatus().equals("desativado")) {
                            System.out.println("teste Status");

                            JOptionPane.showMessageDialog(null, "Cliente " + c.getNome() + " Ja está Cadastrado \n"
                                    + "Mas esta desativado para ativa-lo vá para o menu Alterar ");
                        } else {
                            System.out.println("teste Status senao");
                            JOptionPane.showMessageDialog(null, "Cliente " + c.getNome() + " Ja está Cadastrado ");
                        }
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "Cpf Inválido Verfique se Você Digitou Corretamente ! ");
                }

            } else {
                JOptionPane.showMessageDialog(null, "Por Favor Preencha todos os Campos ");
            }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Exceção Lançada ao tentar Cadastrar Cliente " + ex);
        }


    }//GEN-LAST:event_btnCadastrarActionPerformed

    private void btnLimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimparActionPerformed
        // TODO add your handling code here:
        txtNome.setText("");
        txtEndereco.setText("");
        txtTel1.setText("");
        txtTel2.setText("");

        txtCpf.setEditable(true);
        txtNome.setEditable(true);
        txtEndereco.setEditable(true);
        txtTel1.setEditable(true);
        txtTel2.setEditable(true);


    }//GEN-LAST:event_btnLimparActionPerformed

    private void Bt_Pesq_ConsuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Bt_Pesq_ConsuActionPerformed
        // TODO add your handling code here:
        if (!txtPesquisa.getText().equals("")) {
            try {
                ClienteDAO cdao = new ClienteDAO();
                DefaultTableModel modelo = new DefaultTableModel(0, 5);

                String[] linha = new String[4];
                Vector colunas = new Vector(4);


                //ROOSEVELT ESTEVE AQUI 



                List<Cliente> lista = null;
                try {
                    lista = cdao.ListarTodos(txtPesquisa.getText());
                } catch (Exception ex) {
                    ex.printStackTrace();
                    // Logger.getLogger(JPessoa.class.getName()).log(Level.SEVERE, null, ex);
                }


                String[] coluna = new String[]{"Nome", "Endereço", "Fone 1", "Fone 2"};
                modelo.setColumnIdentifiers(coluna);


                //Inserindo dados na tabela modelo
                for (Cliente c : lista) {
                    linha[0] = c.getNome() + "";
                    linha[1] = c.getEndereco();
                    linha[2] = c.getTel1();
                    linha[3] = c.getTel2();
                    modelo.addRow(linha);
                }
                tblPesquisaCliente.setModel(modelo);



            } catch (Exception ex) {
                ex.printStackTrace();
                System.out.println("Exceção Pesquisar  " + ex);
            }
        } else {
            JOptionPane.showMessageDialog(null, "Nome do Cliente não Informado", "Erro na Pesquisa", JOptionPane.INFORMATION_MESSAGE);
        }

    }//GEN-LAST:event_Bt_Pesq_ConsuActionPerformed

    private void Bt_Consu_ListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Bt_Consu_ListActionPerformed
        // TODO add your handling code here:

        try {
            ClienteDAO cd = new ClienteDAO();
            DefaultTableModel modelo = new DefaultTableModel(0, 5);
            List<Cliente> lista = null;
            try {
                lista = cd.ListarTodos();
            } catch (Exception ex) {
                ex.printStackTrace();
                // Logger.getLogger(JPessoa.class.getName()).log(Level.SEVERE, null, ex);
            }


            String[] linha = new String[5];
            Vector colunas = new Vector(5);
            if (lista != null) {
                //Define o nome das colunas da tabela Modelo
                colunas.add("Nome");
                colunas.add("Endereço");
                colunas.add("Fone 1");
                colunas.add("Fone 2");


                modelo.setColumnIdentifiers(colunas);

                for (Cliente c : lista) {
                    linha[0] = c.getNome() + "";
                    linha[1] = c.getEndereco();
                    linha[2] = c.getTel1();
                    linha[3] = c.getTel2();


                    modelo.addRow(linha);
                }
                tblPesquisaCliente.setModel(modelo);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            System.out.println(" exceção Listar empresa  " + ex);
        }


    }//GEN-LAST:event_Bt_Consu_ListActionPerformed

    private void Bt_Exc_PesqActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Bt_Exc_PesqActionPerformed
        // TODO add your handling code here:
        if (!txtPesquisaExcluir.getText().equals("")) {
            try {
                ClienteDAO cdao = new ClienteDAO();
                DefaultTableModel modelo = new DefaultTableModel(0, 5);

                String[] linha = new String[5];
                Vector colunas = new Vector(5);


                //ROOSEVELT ESTEVE AQUI 



                List<Cliente> lista = null;
                try {
                    lista = cdao.ListarTodos(txtPesquisaExcluir.getText());
                } catch (Exception ex) {
                    ex.printStackTrace();
                    // Logger.getLogger(JPessoa.class.getName()).log(Level.SEVERE, null, ex);
                }


                String[] coluna = new String[]{"Nome", "Cpf", "Endereço", "Fone 1", "Fone 2"};
                modelo.setColumnIdentifiers(coluna);


                //Inserindo dados na tabela modelo
                for (Cliente c : lista) {
                    linha[0] = c.getNome();
                    linha[1] = c.getCpf();
                    linha[2] = c.getEndereco();
                    linha[3] = c.getTel1();
                    linha[4] = c.getTel2();
                    modelo.addRow(linha);
                }
                tblPesquisaExc.setModel(modelo);



            } catch (Exception ex) {
                ex.printStackTrace();
                System.out.println("Exceção Pesquisar  " + ex);
            }
        } else {
            JOptionPane.showMessageDialog(null, "Nome do Cliente não Informado", "Erro na Pesquisa", JOptionPane.INFORMATION_MESSAGE);
        }

    }//GEN-LAST:event_Bt_Exc_PesqActionPerformed

    private void btnExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExcluirActionPerformed
        try {
            if (tblPesquisaExc.getRowCount() != 0) {
                System.out.println("linhas " + tblPesquisaExc.getRowCount());
                ClienteDAO cd = new ClienteDAO();
                Cliente c = null;
                c = cd.pesquisa(tblPesquisaExc.getValueAt(0, 1).toString());
                if (!c.getStatus().equals("desativado")) {
                    int resposta = JOptionPane.showConfirmDialog(null, "Tem certeza que deseja Excluir o Cliente " + c.getNome());

                    if (resposta == 0) {
                        cd.remover(c.getCpf());
                        JOptionPane.showMessageDialog(null, " Cliente Excluido com Sucesso ");
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "Este Cliente ja foi excluido ");
                }
            } else {
                JOptionPane.showMessageDialog(null, "Nenhum Cliente Encotrado ");

            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Exceção na tentativa de Exclusão " + ex.getMessage());

        }

    }//GEN-LAST:event_btnExcluirActionPerformed

    private void Bt_Pesq_AltActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Bt_Pesq_AltActionPerformed

        if (!txtPesquisaAlterar.getText().equals("")) {

            try {
                PessoaDAO pd = new PessoaDAO();
                ClienteDAO cd = new ClienteDAO();
                c = null;
                c = cd.pesquisa(txtPesquisaAlterar.getText());

                txtNomeAlterar.setText(c.getNome());
                txtEnderecoAlterar.setText(c.getEndereco());
                txtTel1Alterar.setText(c.getTel1());
                txtTel2Alterar.setText(c.getTel2());
                jComboBoxStatus.setSelectedItem(c.getStatus());


            } catch (Exception ex) {
            }
        } else {
            JOptionPane.showMessageDialog(null, "Nenhum Cliente Informado no Campo de Texto", "Erro na Alteração", JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_Bt_Pesq_AltActionPerformed

    private void btnAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAlterarActionPerformed
        // TODO add your handling code here:
        try {
            PessoaDAO pd = new PessoaDAO();
            ClienteDAO cd = new ClienteDAO();

            c.setNome(txtNomeAlterar.getText());
            c.setEndereco(txtEnderecoAlterar.getText());
            c.setTel1(txtTel1Alterar.getText());
            c.setTel2(txtTel2Alterar.getText());
            c.setStatus(jComboBoxStatus.getSelectedItem().toString());



            if (pd.Alterar(c) & cd.alterarCliente(c)) {
                JOptionPane.showMessageDialog(null, "Cliente " + c.getNome() + " alterado com Sucesso ");
            } else {
                JOptionPane.showMessageDialog(null, "Problemas ao tentar alterar Cliente " + c.getNome());
            }

            c = null;
        } catch (Exception ex) {
            ex.printStackTrace();
            System.out.println("Exceção cadastrar " + ex);
        }

    }//GEN-LAST:event_btnAlterarActionPerformed

    private void Bt_Alt_LimpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Bt_Alt_LimpActionPerformed
        // TODO add your handling code here:
        txtNomeAlterar.setText("");
        txtEnderecoAlterar.setText("");
        txtTel1Alterar.setText("");
        txtTel2Alterar.setText("");


    }//GEN-LAST:event_Bt_Alt_LimpActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        // public void gerar() throws JRException, SQLException,
        //		ClassNotFoundException {
        // gerando o jasper design
        try {
            String layout = "C:/Users/monitor.DOMAIN/Documents/NetBeansProjects/Mercado_Aberto/src/Frames/report2.jrxml";

            JasperDesign desenho = JRXmlLoader.load(layout);

            // compila o relatório
            JasperReport relatorio = JasperCompileManager.compileReport(desenho);

            // estabelece conexão
            Class.forName("org.postgresql.Driver");
            Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgres", "postgres", "postgres");
            Statement stm = (Statement) con.createStatement();
            //Statement stmAux = con.createStatement();
            String query = "select * from pessoa p,func f where f.cod_pessoa = p.cod_pessoa ";
            //String queryAux = "";

            //query = "select * from che_cheque, ban_banco, fun_funcionario where ban_cod_banco = che_ban_cheque and fun_cpf_funcionario = che_rec_cheque";
            // queryAux = "select * from che_cheque, ban_banco, fun_funcionario where ban_cod_banco = che_ban_cheque and fun_cpf_funcionario = che_rec_cheque";


            ResultSet rs = stm.executeQuery(query);
            //ResultSet rsAux = stmAux.executeQuery(queryAux);
            //Long soma = 0L;
            // while (rsAux.next()) {
            //  soma = soma + new Long(rsAux.getString("che_val_cheque"));
            //  }

            // implementação da interface JRDataSource para DataSource ResultSet
            JRResultSetDataSource jrRS = new JRResultSetDataSource(rs);

            // executa o relatório
            Map parametros = new HashMap();

            //String valor = "";
            //while(rsAux.next()){
            //    valor = rsAux.getString("valorTotal");
            //}

            parametros.put("param1", null);

            JasperPrint impressao = JasperFillManager.fillReport(relatorio,
                    parametros, jrRS);

            // exibe o resultado
            JasperViewer viewer = new JasperViewer(impressao, false);
            con.close();
            viewer.show();
        } catch (JRException e) {
        } catch (SQLException e) {
        } catch (ClassNotFoundException e) {
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void txtCpfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCpfActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtCpfActionPerformed

    private void txtPesquisaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPesquisaKeyPressed

        try {
            ClienteDAO cd = new ClienteDAO();
            DefaultTableModel modelo = new DefaultTableModel(0, 5);
            List<Cliente> lista = null;
            try {
                lista = cd.ListarTodos(txtPesquisa.getText());
            } catch (Exception ex) {
                ex.printStackTrace();
                // Logger.getLogger(JPessoa.class.getName()).log(Level.SEVERE, null, ex);
            }


            String[] linha = new String[4];
            Vector colunas = new Vector(4);
            if (lista != null) {
                //Define o nome das colunas da tabela Modelo
                colunas.add("Nome");
                colunas.add("Endereço");
                colunas.add("Fone 1");
                colunas.add("Fone 2");


                modelo.setColumnIdentifiers(colunas);

                for (Cliente c : lista) {
                    linha[0] = c.getNome() + "";
                    linha[1] = c.getEndereco();
                    linha[2] = c.getTel1();
                    linha[3] = c.getTel2();


                    modelo.addRow(linha);
                }
                tblPesquisaCliente.setModel(modelo);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            System.out.println(" exceção Listar empresa  " + ex);
        }


    }//GEN-LAST:event_txtPesquisaKeyPressed

    private void txtCpfKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCpfKeyPressed
        try {
        } catch (Exception ex) {
        }
    }//GEN-LAST:event_txtCpfKeyPressed

    private void VerificarCpfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_VerificarCpfActionPerformed
        try {
            PessoaDAO pd = new PessoaDAO();
            ClienteDAO cd = new ClienteDAO();
            c = cd.pesquisa(txtCpf.getText());
            Pessoa p = pd.pesquisa(txtCpf.getText());

            if (ValidacaoCpf.calculaCPF(txtCpf.getText())) {
                if (c.getCpf().equals(txtCpf.getText())) {
                    if (c.getStatus().equals("desativado")) {

                        txtCpf.setEditable(false);

                        txtNome.setText(c.getNome());
                        txtNome.setEditable(false);
                        txtEndereco.setText(c.getEndereco());
                        txtEndereco.setEditable(false);

                        txtTel1.setText(c.getTel1());
                        txtTel1.setEditable(false);
                        txtTel2.setText(c.getTel2());
                        txtTel2.setEditable(false);

                        JOptionPane.showMessageDialog(null, "Este CPF é de um Funcionario que esta Desativado !\n"
                                + "Para ativa-lo va para o menu Alterar !");

                    } else {
                        JOptionPane.showMessageDialog(null, " Cliente " + c.getNome() + " já cadastrado ");
                        txtCpf.setEditable(false);

                        txtNome.setText(p.getNome());
                        txtNome.setEditable(false);
                        txtEndereco.setText(p.getEndereco());
                        txtEndereco.setEditable(false);


                        txtTel1.setText(p.getTel1());
                        txtTel1.setEditable(false);
                        txtTel2.setText(p.getTel2());
                        txtTel2.setEditable(false);

                    }
                } else if (p.getCpf().equals(txtCpf.getText())) {

                    txtNome.setText(p.getNome());
                    txtNome.setEditable(false);
                    txtEndereco.setText(p.getEndereco());
                    txtEndereco.setEditable(false);
                    txtTel1.setText(p.getTel1());
                    txtTel1.setEditable(false);
                    txtTel2.setText(p.getTel2());
                    txtTel2.setEditable(false);

                }
            } else {
                JOptionPane.showMessageDialog(null, " Número de Cpf Invalido ");
            }

        } catch (Exception ex) {
        }
    }//GEN-LAST:event_VerificarCpfActionPerformed

    private void jTabbedPane1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTabbedPane1KeyPressed
        try {
            ClienteDAO cd = new ClienteDAO();
            //  cd.ListarTodos(txPesquisa.g)








        } catch (Exception ex) {
        }
    }//GEN-LAST:event_jTabbedPane1KeyPressed

    private void txtPesquisaExcluirKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPesquisaExcluirKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            if (!txtPesquisaExcluir.getText().equals("")) {
                try {
                    ClienteDAO cdao = new ClienteDAO();
                    DefaultTableModel modelo = new DefaultTableModel(0, 5);

                    String[] linha = new String[5];
                    Vector colunas = new Vector(5);


                    //ROOSEVELT ESTEVE AQUI 



                    List<Cliente> lista = null;
                    try {
                        lista = cdao.ListarTodos(txtPesquisaExcluir.getText());
                    } catch (Exception ex) {
                        ex.printStackTrace();
                        // Logger.getLogger(JPessoa.class.getName()).log(Level.SEVERE, null, ex);
                    }


                    String[] coluna = new String[]{"Nome", "Cpf", "Endereço", "Fone 1", "Fone 2"};
                    modelo.setColumnIdentifiers(coluna);


                    //Inserindo dados na tabela modelo
                    for (Cliente c : lista) {
                        linha[0] = c.getNome();
                        linha[1] = c.getCpf();
                        linha[2] = c.getEndereco();
                        linha[3] = c.getTel1();
                        linha[4] = c.getTel2();
                        modelo.addRow(linha);
                    }
                    tblPesquisaExc.setModel(modelo);



                } catch (Exception ex) {
                    ex.printStackTrace();
                    System.out.println("Exceção Pesquisar  " + ex);
                }
            } else {
                JOptionPane.showMessageDialog(null, "Nome do Cliente não Informado", "Erro na Pesquisa", JOptionPane.INFORMATION_MESSAGE);
            }
        }
    }//GEN-LAST:event_txtPesquisaExcluirKeyPressed

    private void txtPesquisaAlterarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPesquisaAlterarKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            if (!txtPesquisaAlterar.getText().equals("")) {

                try {
                    PessoaDAO pd = new PessoaDAO();
                    ClienteDAO cd = new ClienteDAO();
                    c = null;
                    c = cd.pesquisa(txtPesquisaAlterar.getText());

                    txtNomeAlterar.setText(c.getNome());
                    txtEnderecoAlterar.setText(c.getEndereco());
                    txtTel1Alterar.setText(c.getTel1());
                    txtTel2Alterar.setText(c.getTel2());
                    jComboBoxStatus.setSelectedItem(c.getStatus());


                } catch (Exception ex) {
                }
            } else {
                JOptionPane.showMessageDialog(null, "Nenhum Cliente Informado no Campo de Texto", "Erro na Alteração", JOptionPane.INFORMATION_MESSAGE);
            }
        }
    }//GEN-LAST:event_txtPesquisaAlterarKeyPressed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                //new Tela_Produto().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Bt_Alt_Limp;
    private javax.swing.JButton Bt_Consu_List;
    private javax.swing.JButton Bt_Exc_Pesq;
    private javax.swing.JButton Bt_Pesq_Alt;
    private javax.swing.JButton Bt_Pesq_Consu;
    private javax.swing.JButton VerificarCpf;
    private javax.swing.JButton btnAlterar;
    private javax.swing.JButton btnCadastrar;
    private javax.swing.JButton btnExcluir;
    private javax.swing.JButton btnLimpar;
    private javax.swing.JButton jButton2;
    private javax.swing.JComboBox jComboBoxStatus;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable tblPesquisaCliente;
    private javax.swing.JTable tblPesquisaExc;
    private javax.swing.JTextField txtCpf;
    private javax.swing.JTextField txtEndereco;
    private javax.swing.JTextField txtEnderecoAlterar;
    private javax.swing.JTextField txtNome;
    private javax.swing.JTextField txtNomeAlterar;
    private javax.swing.JTextField txtPesquisa;
    private javax.swing.JTextField txtPesquisaAlterar;
    private javax.swing.JTextField txtPesquisaExcluir;
    private javax.swing.JTextField txtTel1;
    private javax.swing.JTextField txtTel1Alterar;
    private javax.swing.JTextField txtTel2;
    private javax.swing.JTextField txtTel2Alterar;
    // End of variables declaration//GEN-END:variables
}
